package com.zhkj.txg.module.mine.model

import com.zhkj.lib.http.BaseManager
import com.zhkj.lib.http.BaseResponse
import com.zhkj.lib.http.ResponseSubscribeListener
import com.zhkj.lib.http.SubscribeListener
import com.zhkj.lib.utils.AccountManager
import com.zhkj.txg.module.home.entity.HotGoodsResponse
import com.zhkj.txg.module.home.entity.RechargeListResponse
import com.zhkj.txg.module.mine.entity.*
import com.zhkj.txg.module.mine.vm.EditUserInfoResponse
import com.zhkj.txg.module.order.entity.OrderPayResponse
import io.reactivex.disposables.Disposable
import retrofit2.http.Query

class MineManager : BaseManager<MineApi>(MineApi::class.java) {

    /**
     * 获取热门商品
     */
    fun hotGoods(
        token: String,
        page: Int,
        numb: Int,
        listener: SubscribeListener<HotGoodsResponse>
    ): Disposable {
        val hotGoods = apiService.hotGoods(token, page, numb)
        return subscribe(hotGoods, ResponseSubscribeListener(listener))
    }

    /**
     * 获取用户数据
     */
    fun userCenter(
        token: String,
        listener: SubscribeListener<UserCenterResponse>
    ): Disposable {
        val userCenter = apiService.userCenter(token)
        return subscribe(userCenter, ResponseSubscribeListener(listener))
    }

    /**
     * 修改用户资料
     */
    fun userInfoEdit(
        token: String, nickname: String, birthday: String, gender: String,
        province: Int, city: Int, district: Int, avatar: String,
        listener: SubscribeListener<EditUserInfoResponse>
    ): Disposable {
        val userInfoChange = apiService.userInfoChange(
            token, nickname, birthday, gender,
            province, city, district, avatar
        )
        return subscribe(userInfoChange, ResponseSubscribeListener(listener))
    }

    /**
     * 获取余额列表
     */
    fun balanceList(
        token: String, page: Int, numb: Int,
        listener: SubscribeListener<BalanceListResponse>
    ): Disposable {
        val balanceList = apiService.balanceList(token, page, numb)
        return subscribe(balanceList, ResponseSubscribeListener(listener))
    }

    /**
     * 余额充值
     */
    fun recharge(
        token: String, money: String, payType: String, shopId: String,
        listener: SubscribeListener<OrderPayResponse>
    ): Disposable {
        val recharge = apiService.recharge(token, money, payType, shopId)
        return subscribe(recharge, ResponseSubscribeListener(listener))
    }

    /**
     * 获取体现配置
     */
    fun withdrawConfig(
        token: String,
        listener: SubscribeListener<WithdrawConfigResponse>
    ): Disposable {
        val withdrawConfig = apiService.getWithdrawConfig(token)
        return subscribe(withdrawConfig, ResponseSubscribeListener(listener))
    }

    /**
     * 提现
     */
    fun withdraw(
        token: String, money: String, type: String, withdrawToken: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val withdraw = apiService.withdraw(token, money, type, withdrawToken)
        return subscribe(withdraw, ResponseSubscribeListener(listener))
    }

    /**
     * 退出登录
     */
    fun logout(token: String, listener: SubscribeListener<BaseResponse>): Disposable {
        val logout = apiService.logout(token)
        return subscribe(logout, ResponseSubscribeListener(listener))
    }

    /**
     * 获取收藏列表
     */
    fun collectionList(
        token: String, shopId:String, page: Int, rows: Int, type: String,
        listener: SubscribeListener<CollectionListResponse>
    ): Disposable {
        val collectionList = apiService.collectionList(token,shopId, page, rows, type)
        return subscribe(collectionList, ResponseSubscribeListener(listener))
    }

    /**
     * 取消收藏
     */
    fun cancelCollection(
        token: String, collectionIds: String, type: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val cancelCollection = apiService.cancelCollection(token, collectionIds, type)
        return subscribe(cancelCollection, ResponseSubscribeListener(listener))
    }

    /**
     * 优惠全列表
     */
    fun couponList(
        token: String, useType: Int, apiType: Int, status: Int, page: Int, rows: Int,
        listener: SubscribeListener<CouponListResponse>
    ): Disposable {
        val couponList = apiService.couponList(token, useType, apiType, status, page, rows)
        return subscribe(couponList, ResponseSubscribeListener(listener))
    }

    /**
     * 领券中心
     */
    fun couponCenter(
        token: String, useType: Int, page: Int, rows: Int,
        listener: SubscribeListener<CouponCenterResponse>
    ): Disposable {
        val couponCenter = apiService.couponCenter(token, useType, page, rows)
        return subscribe(couponCenter, ResponseSubscribeListener(listener))
    }

    /**
     * 领取优惠券
     */
    fun getCoupon(
        token: String, id: Long,
        listener: SubscribeListener<CouponGetResponse>
    ): Disposable {
        val coupon = apiService.getCoupon(token, id)
        return subscribe(coupon, ResponseSubscribeListener(listener))
    }

    /**
     * 浏览历史
     */
    fun visitLog(
        token: String, page: Int, numb: Int,
        listener: SubscribeListener<VisitLogResponse>
    ): Disposable {
        val visitLog = apiService.visitLog(token, page, numb)
        return subscribe(visitLog, ResponseSubscribeListener(listener))
    }

    /**
     * 获取已发表文章列表
     */
    fun publishArticleList(
        token: String, page: Int, numb: Int,
        listener: SubscribeListener<PublishListResponse>
    ): Disposable {
        val publishList = apiService.publishList(token, page, numb)
        return subscribe(publishList, ResponseSubscribeListener(listener))
    }

    /**
     * 删除已发表文章
     */
    fun deletePublishArticle(
        token: String, id: Long,
        listener: SubscribeListener<DeleteArticleResponse>
    ): Disposable {
        val deleteArticle = apiService.deleteArticle(token, id)
        return subscribe(deleteArticle, ResponseSubscribeListener(listener))
    }

    /**
     * 绑定微信账户信息
     */
    fun bindWeChat(
        token: String, code: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val bindWeChat = apiService.bindWeChat(token, code)
        return subscribe(bindWeChat, ResponseSubscribeListener(listener))
    }

    /**
     * 获取用户绑定数据
     */
    fun userBind(
        token: String,
        listener: SubscribeListener<UserBindResponse>
    ): Disposable {
        val userBindData = apiService.getUserBindData(token)
        return subscribe(userBindData, ResponseSubscribeListener(listener))
    }

    /**
     * 绑定支付宝账户
     */
    fun bindAliPay(
        token: String, name: String, account: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val bindAliPay = apiService.bindAliPay(token, name, account)
        return subscribe(bindAliPay, ResponseSubscribeListener(listener))
    }

    /**
     * 设置 - 关于我们
     */
    fun aboutUs(listener: SubscribeListener<AboutUsResponse>): Disposable {
        val aboutUs = apiService.aboutUs()
        return subscribe(aboutUs, ResponseSubscribeListener(listener))
    }

    /**
     * 设置 - 使用指南
     */
    fun guideList(listener: SubscribeListener<GuideListResponse>): Disposable {
        val guideList = apiService.guideList()
        return subscribe(guideList, ResponseSubscribeListener(listener))
    }

    /**
     * 删除足迹
     */
    fun deleteVisitLog(token: String, ids: String, listener: SubscribeListener<BaseResponse>): Disposable {
        val deleteVisitLog = apiService.deleteVisitLog(token, ids)
        return subscribe(deleteVisitLog, ResponseSubscribeListener(listener))
    }

    /**
     * 获取系统通知列表
     */
    fun notification(
        token: String,
        page: Int,
        numb: Int,
        listener: SubscribeListener<NotificationResponse>
    ): Disposable {
        val notification = apiService.notification(token, page, numb)
        return subscribe(notification, ResponseSubscribeListener(listener))
    }

    /**
     * 获取售后列表
     */
    fun refundList(token: String, page: Int, rows: Int, listener: SubscribeListener<RefundListResponse>): Disposable {
        val refundList = apiService.refundList(token, page, rows)
        return subscribe(refundList, ResponseSubscribeListener(listener))
    }

    /**
     * 获取会员分销体现配置
     */
    fun memberWithdrawConfig(
        token: String,
        listener: SubscribeListener<WithdrawConfigResponse>
    ): Disposable {
        val withdrawConfig = apiService.withdrawConfig(token)
        return subscribe(withdrawConfig, ResponseSubscribeListener(listener))
    }

    /**
     * 会员分销提现
     */
    fun memberWithdraw(
        token: String, money: String, type: String, withdrawToken: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val withdraw = apiService.memberWithdraw(token, money, type, withdrawToken)
        return subscribe(withdraw, ResponseSubscribeListener(listener))
    }

    /**
     * 会员分销提现日志
     */
    fun memberWithdrawList(
        page: Int,
        rows: Int,
        date: String,
        listener: SubscribeListener<WithdrawListResponse>
    ): Disposable {
        val memberWithdrawList = apiService.memberWithdrawList(AccountManager.getToken(), page, rows, date)
        return subscribe(memberWithdrawList, ResponseSubscribeListener(listener))
    }

    /**
     * 会员分销提现日志
     */
    fun withdrawList(
        page: Int,
        rows: Int,
        date: String,
        listener: SubscribeListener<WithdrawListResponse>
    ): Disposable {
        val memberWithdrawList = apiService.withdrawList(AccountManager.getToken(), page, rows, date)
        return subscribe(memberWithdrawList, ResponseSubscribeListener(listener))
    }

    /**
     * 我的邀请人
     */
    fun getReferrer(
        listener: SubscribeListener<ReferrerResponse>
    ): Disposable {
        val memberWithdrawList = apiService.getReferrer(AccountManager.getToken())
        return subscribe(memberWithdrawList, ResponseSubscribeListener(listener))
    }

    /**
     * 冲值列表
     * */
    fun getRechargeList(
        listener: SubscribeListener<RechargeListResponse>
    ): Disposable {
        val userCardList = apiService.getRechargeList(AccountManager.getToken())
        return subscribe(userCardList, ResponseSubscribeListener(listener))
    }

    /**
     * 充值说明
     * */
    fun getRecharge(listener: SubscribeListener<BaseResponse>): Disposable {
        val userCardList = apiService.getRecharge(AccountManager.getToken())
        return subscribe(userCardList, ResponseSubscribeListener(listener))
    }

    /**
     * 等级列表
     * */
    fun getUserCardList(
        listener: SubscribeListener<DiamondResponse>
    ): Disposable {
        val userCardList = apiService.getUserCardList(AccountManager.getToken())
        return subscribe(userCardList, ResponseSubscribeListener(listener))
    }

    /**
     * 会员提交订单
     * */
    fun getSubmitOrder(
        cardId: String, validDate: String, shopId: String,
        listener: SubscribeListener<SubmitOrderResponse>
    ): Disposable {
        val submitOrder = apiService.getSubmitOrder(AccountManager.getToken(), cardId, validDate, shopId)
        return subscribe(submitOrder, ResponseSubscribeListener(listener))
    }

    /**
     * 会员订单支付
     * */
    fun getPayOrder(
        orderSn: String, payType: String,
        listener: SubscribeListener<PayOrderResponse>
    ): Disposable {
        val payOrder = apiService.getPayOrder(AccountManager.getToken(), orderSn, payType)
        return subscribe(payOrder, ResponseSubscribeListener(listener))
    }

    /**
     * 问题反馈提交
     * */
    fun setFeedback(
        content: String, images: String?,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val feedback = apiService.setFeedback(AccountManager.getToken(), content, images)
        return subscribe(feedback, ResponseSubscribeListener(listener))
    }


    /**
     * 获取常见问题列表
     * */
    fun getCommonProblem(
        listener: SubscribeListener<ProblemResponse>
    ): Disposable {
        val commonProblem = apiService.getCommonProblem(AccountManager.getToken())
        return subscribe(commonProblem, ResponseSubscribeListener(listener))
    }

    /**
     * 获取常见问题详情
     * */
    fun getProblemDetail(
        id: String, listener: SubscribeListener<ProblemDetailResponse>
    ): Disposable {
        val problemDetail = apiService.getProblemDetail(AccountManager.getToken(), id)
        return subscribe(problemDetail, ResponseSubscribeListener(listener))
    }

    /**
     * 版本更新
     * */
    fun getVersion(
        listener: SubscribeListener<VersionResponse>
    ): Disposable {
        val version = apiService.getVersion(AccountManager.getToken())
        return subscribe(version, ResponseSubscribeListener(listener))
    }

}